import java.io.FileNotFoundException
import java.io.IOException
import scala.io.Source
object TryCatch {
  def main(args: Array[String]): Unit = {
    try {
      val source = Source.fromFile("xxx.txt")
      for (line <- source.getLines) {
        println(line)
      }
      source.close()
    } catch {
      case exception: FileNotFoundException => println("发生异常：文件不存在")
      case exception: IOException => println("发生异常：文件读取错误")
    }
  }
}
